package stu.day25_day32.day32.tmp;

import java.util.Scanner;

public class hw1 {


    public static void main(String[] args) {
        //输入
        Scanner sc = new Scanner(System.in);
        int len = Integer.parseInt(sc.nextLine());
        char[] ch = sc.nextLine().toCharArray();
        //遍历
        int min = len;
        int k = (int)Math.sqrt(len);
        for(int i=1;i<=k;i++){
            if(len%i==0){
                int j = len/i;
                min = Math.min(min,cal(i,j,ch));
                System.out.println(i+" "+j+" "+min);
                min = Math.min(min,cal(j,i,ch));
                System.out.println(j+" "+i+" "+min);
            }
        }
        System.out.println(min);
    }

    public static int cal(int i,int j,char[] ch){
        int num = 0;
        char flag = '1';
        char[][] arr = new char[i][j];
        for(int p=0;p<i;p++){
            for(int q=0;q<j;q++){
                arr[p][q]=ch[p*j+q] ;
            }
        }

        for(int p=0;p<i;p++){
            for(int q=0;q<j;q++){
               if(arr[p][q]!=flag){
                   num += 1;
                   dfs(p,q,i,j,arr[p][q],arr);
               }
            }
        }
        return num;
    }

    public static void dfs(int p,int q,int i,int j,char cr,char[][] arr){
        if(p>=0&&p<i&&q>=0&&q<j){
            if(arr[p][q]==cr){
                arr[p][q]='1';
                dfs(p+1,q,i,j,cr,arr);
                dfs(p-1,q,i,j,cr,arr);
                dfs(p,q+1,i,j,cr,arr);
                dfs(p,q-1,i,j,cr,arr);
            }
        }
    }

}
